package com.hrt.manage.comments.service.Impl;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hrt.bean.Comments;
import com.hrt.manage.comments.dao.CommentsDao;
import com.hrt.manage.comments.service.CommentsService;

@Transactional
@Service("commentsService")
public class CommentsServiceImpl implements CommentsService{
	
	@Autowired
	private CommentsDao commentsDao;
	
	/**
	 * 保存实体
	 * */
	@Override
	public void addComments(Comments comments) {
		this.commentsDao.saveEntity(comments);
	}

	/**
	 * 更新实体
	 * */
	@Override
	public void updateComments(Comments comments) {
		this.commentsDao.updateEntity(comments);
	}

	/**
	 * 删除实体
	 * */
	@Override
	public void delComments(Long id) {
		this.commentsDao.deleteEntity(id);
	}

	/**
	 * 按id查询实体
	 * */
	@Override
	public Comments getById(Long id) {
		
		return this.commentsDao.getById(id);
	}

	/**
	 * 查询所有
	 * */
	@Override
	public List<Comments> searchAll() {
		
		return this.commentsDao.findAll();
	}

	/**
	 * 按是否删除查询
	 */
	@Override
	public List<Comments> searchDelAll() {
		
		return this.commentsDao.findDelAll();
	}

	/**
	 * 按id列表查询实体
	 * */
	@Override
	public List<Comments> getByIds(Long[] ids) {
		
		return this.commentsDao.getByIds(ids);
	}

	/**分页*/
	@Override
	public Long totalCount() {
		
		return this.commentsDao.totalCount();
	}
	@Override
	public List<Comments> queryByPage(int pageIndex, int pageSize) {
		
		return this.commentsDao.queryByPage(pageIndex, pageSize);
	}

	/**获取数据库的当前Timestamp形式的时间*/
	@Override
	public Timestamp getDate() {
		return this.commentsDao.getDate();
	}

	/**删除选中的数据*/
	@Override
	public void deleteById(Long[] ids) throws Exception {
		List<Comments> delResult = this.commentsDao.getByIds(ids);
		for (Comments  comm: delResult) {
			comm.setIsdelete(new Integer(1));
			this.commentsDao.updateEntity(comm);
		}
	}

}
